package org.bigdata.framework.core.protocol;

import java.util.HashMap;
import java.util.List;

import org.apache.log4j.Logger;
import org.bigdata.framework.core.model.BaikeCategory;
import org.bigdata.framework.core.model.BaikeEntry;
import org.bigdata.framework.core.model.BaikeEntryRecord;
import org.bigdata.framework.core.model.BaikeEntryVersion;
import org.bigdata.framework.core.model.BaikeNews;
import org.bigdata.framework.core.model.BaikeTemplate;
import org.bigdata.framework.core.service.IBaikeCategoryService;
import org.bigdata.framework.core.service.IBaikeEntryRecordService;
import org.bigdata.framework.core.service.IBaikeEntryService;
import org.bigdata.framework.core.service.IBaikeEntryVersionService;
import org.bigdata.framework.core.service.IBaikeNewsService;
import org.bigdata.framework.core.service.IBaikeTemplateService;
import org.bigdata.framework.core.utils.MybatisPlusTools;
import org.springframework.beans.factory.annotation.Autowired;

import com.baomidou.mybatisplus.plugins.Page;

/**
 * 知识百科模块
 * 
 * @author vimes 2017-2-15 09:50:07
 */
public class BaikeService implements IBaikeService {

	private static final Logger LOG = Logger.getLogger(BaseService.class);

	@Autowired
	private IBaikeCategoryService baikeCategoryService;
	@Autowired
	private IBaikeEntryService baikeEntryService;
	@Autowired
	private IBaikeEntryRecordService baikeEntryRecordService;
	@Autowired
	private IBaikeTemplateService baikeTemplateService;
	@Autowired
	private IBaikeEntryVersionService baikeEntryVersionService;
	@Autowired
	private IBaikeNewsService baikeNewsService;

	@Override
	public BaikeCategory saveBaikeCategory(BaikeCategory baikeCategory) {
		// TODO Auto-generated method stub
		boolean r = baikeCategoryService.insert(baikeCategory);
		if (r) {
			return baikeCategory;
		}
		return null;
	}

	@Override
	public BaikeCategory editBaikeCategory(BaikeCategory baikeCategory) {
		// TODO Auto-generated method stub
		boolean r = baikeCategoryService.updateAllColumnById(baikeCategory);
		if (r) {
			return baikeCategory;
		}
		return null;
	}

	@Override
	public void deleteBaikeCategory(BaikeCategory baikeCategory) {
		// TODO Auto-generated method stub
		boolean r = baikeCategoryService.deleteById(baikeCategory.getId());
		if (r) {
			System.out.println("baikeCategory 删除成功>>>" + baikeCategory.getId());
		}
	}

	@Override
	public BaikeCategory findBaikeCategory(Integer id) {
		// TODO Auto-generated method stub
		return baikeCategoryService.selectById(id);
	}

	@Override
	public List<BaikeCategory> getBaikeCategory() {
		// TODO Auto-generated method stub
		return baikeCategoryService.selectList(null);
	}
	
	@Override
	public List<BaikeCategory> getBaikeCategory(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {
		return baikeCategoryService.selectPage(
				new Page<BaikeCategory>(pageNumber, pageSize),
				new MybatisPlusTools<BaikeCategory>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getBaikeCategoryCount(HashMap<String, Object> queryParams) {
		return baikeCategoryService.selectCount(new MybatisPlusTools<BaikeCategory>()
				.getEwByCount(queryParams));
	}
	
	@Override
	public BaikeTemplate saveBaikeTemplate(BaikeTemplate baikeTemplate) {
		// TODO Auto-generated method stub
		boolean r = baikeTemplateService.insert(baikeTemplate);
		if (r) {
			return baikeTemplate;
		}
		return null;
	}

	@Override
	public BaikeTemplate editBaikeTemplate(BaikeTemplate baikeTemplate) {
		// TODO Auto-generated method stub
		boolean r = baikeTemplateService.updateAllColumnById(baikeTemplate);
		if (r) {
			return baikeTemplate;
		}
		return null;
	}

	@Override
	public void deleteBaikeTemplate(BaikeTemplate baikeTemplate) {
		// TODO Auto-generated method stub
		boolean r = baikeTemplateService.deleteById(baikeTemplate.getId());
		if (r) {
			System.out.println("baikeTemplate 删除成功>>>" + baikeTemplate.getId());
		}
	}

	@Override
	public BaikeTemplate findBaikeTemplate(Integer id) {
		// TODO Auto-generated method stub
		return baikeTemplateService.selectById(id);
	}

	@Override
	public List<BaikeTemplate> getBaikeTemplate(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {
		if(queryParams!=null && !"".equals(queryParams)){
			queryParams.put("^,sort", "asc");
		}
		return baikeTemplateService.selectPage(
				new Page<BaikeTemplate>(pageNumber, pageSize),
				new MybatisPlusTools<BaikeTemplate>().getEwByList(queryParams))
				.getRecords();
	}
	@Override
	public Integer getBaikeTemplateCount(HashMap<String, Object> queryParams) {
		return baikeTemplateService.selectCount(new MybatisPlusTools<BaikeTemplate>()
				.getEwByCount(queryParams));
	}
	@Override
	public BaikeEntry saveBaikeEntry(BaikeEntry baikeEntry) {
		// TODO Auto-generated method stub 
		boolean r = baikeEntryService.insert(baikeEntry);
		if (r) {
			return baikeEntry;
		}
		return null;
	}

	@Override
	public BaikeEntry editBaikeEntry(BaikeEntry baikeEntry) {
		// TODO Auto-generated method stub
		boolean r = baikeEntryService.updateAllColumnById(baikeEntry);
		if (r) {
			return baikeEntry;
		}
		return null;
	}

	@Override
	public void deleteBaikeEntry(BaikeEntry baikeEntry) {
		// TODO Auto-generated method stub
		boolean r = baikeEntryService.deleteById(baikeEntry.getId());
		if (r) {
			System.out.println("baikeEntry 删除成功>>>" + baikeEntry.getId());
		}

	}

	@Override
	public BaikeEntry findBaikeEntry(String id) {
		// TODO Auto-generated method stub
		return baikeEntryService.selectById(id);
	}

	@Override
	public List<BaikeEntry> getBaikeEntry(HashMap<String, Object> queryParams,
			int pageNumber, int pageSize) {
		// TODO Auto-generated method stub
		return baikeEntryService.selectPage(
				new Page<BaikeEntry>(pageNumber, pageSize),
				new MybatisPlusTools<BaikeEntry>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getBaikeEntryCount(HashMap<String, Object> queryParams) {
		// TODO Auto-generated method stub
		return baikeEntryService.selectCount(new MybatisPlusTools<BaikeEntry>()
				.getEwByCount(queryParams));
	}

	@Override
	public BaikeEntryVersion saveBaikeEntryVersion(
			BaikeEntryVersion baikeEntryVersion) {
		// TODO Auto-generated method stub
		boolean r = baikeEntryVersionService.insert(baikeEntryVersion);
		if (r) {
			return baikeEntryVersion;
		}
		return null;
	}

	@Override
	public BaikeEntryVersion editBaikeEntryVersion(
			BaikeEntryVersion baikeEntryVersion) {
		// TODO Auto-generated method stub
		boolean r = baikeEntryVersionService.updateAllColumnById(baikeEntryVersion);
		if (r) {
			return baikeEntryVersion;
		}
		return null;
	}

	@Override
	public void deleteBaikeEntryVersion(BaikeEntryVersion baikeEntryVersion) {
		// TODO Auto-generated method stub
		boolean r = baikeEntryVersionService.deleteById(baikeEntryVersion.getId());
		if (r) {
			System.out.println("baikeEntryVersion 删除成功>>>" + baikeEntryVersion.getId());
		}

	}

	@Override
	public BaikeEntryVersion findBaikeEntryVersion(String id) {
		// TODO Auto-generated method stub
		return baikeEntryVersionService.selectById(id);
	}

	@Override
	public List<BaikeEntryVersion> getBaikeEntryVersion(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {
		// TODO Auto-generated method stub
		return baikeEntryVersionService.selectPage(
				new Page<BaikeEntryVersion>(pageNumber, pageSize),
				new MybatisPlusTools<BaikeEntryVersion>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getBaikeEntryVersionCount(HashMap<String, Object> queryParams) {
		// TODO Auto-generated method stub
		return baikeEntryVersionService.selectCount(new MybatisPlusTools<BaikeEntryVersion>().getEwByCount(queryParams));
	}

	@Override
	public BaikeEntryRecord saveBaikeEntryRecord(
			BaikeEntryRecord baikeEntryRecord) {
		// TODO Auto-generated method stub
		boolean r = baikeEntryRecordService.insert(baikeEntryRecord);
		if (r) {
			return baikeEntryRecord;
		}
		return null;
	}

	@Override
	public BaikeEntryRecord editBaikeEntryRecord(
			BaikeEntryRecord baikeEntryRecord) {
		boolean r = baikeEntryRecordService.updateAllColumnById(baikeEntryRecord);
		if (r) {
			return baikeEntryRecord;
		}
		return null;
	}

	@Override
	public void deleteBaikeEntryRecord(BaikeEntryRecord baikeEntryRecord) {
		// TODO Auto-generated method stub
		boolean r = baikeEntryRecordService.deleteById(baikeEntryRecord.getId());
		if (r) {
			System.out.println("baikeEntryRecord 删除成功>>>" + baikeEntryRecord.getId());
		}

	}

	@Override
	public BaikeEntryRecord findBaikeEntryRecord(String id) {
		// TODO Auto-generated method stub
		return baikeEntryRecordService.selectById(id);
	}

	@Override
	public List<BaikeEntryRecord> getBaikeEntryRecord(
			HashMap<String, Object> queryParams, int pageNumber, int pageSize) {
		// TODO Auto-generated method stub
		return baikeEntryRecordService.selectPage(
				new Page<BaikeEntryRecord>(pageNumber, pageSize),
				new MybatisPlusTools<BaikeEntryRecord>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getBaikeEntryRecordCount(HashMap<String, Object> queryParams) {
		// TODO Auto-generated method stub
		return baikeEntryRecordService.selectCount(new MybatisPlusTools<BaikeEntryRecord>()
				.getEwByCount(queryParams));
	}

	@Override
	public BaikeNews saveBaikeNews(BaikeNews baikeNews) {
		boolean r = baikeNewsService.insert(baikeNews);
		if (r) {
			return baikeNews;
		}
		return null;
	}

	@Override
	public BaikeNews editBaikeNews(BaikeNews baikeNews) {
		boolean r = baikeNewsService.updateAllColumnById(baikeNews);
		if (r) {
			return baikeNews;
		}
		return null;
	}

	@Override
	public void deleteBaikeNews(BaikeNews baikeNews) {
		boolean r = baikeNewsService.deleteById(baikeNews.getId());
		if (r) {
			System.out.println("baikeNews 删除成功>>>" + baikeNews.getId());
		}
	}

	@Override
	public BaikeNews findBaikeNews(String id) {
		return baikeNewsService.selectById(id);
	}

	@Override
	public List<BaikeNews> getBaikeNews(HashMap<String, Object> queryParams,
			int pageNumber, int pageSize) {
		return baikeNewsService.selectPage(
				new Page<BaikeNews>(pageNumber, pageSize),
				new MybatisPlusTools<BaikeNews>().getEwByList(queryParams))
				.getRecords();
	}

	@Override
	public Integer getBaikeNewsCount(HashMap<String, Object> queryParams) {
		return baikeNewsService.selectCount(new MybatisPlusTools<BaikeNews>()
				.getEwByCount(queryParams));
	}

}
